package com.hmall.user.constatns;

import com.itheima.utils.ThreadLocalUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class CustomInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)throws Exception {

        String header = request.getHeader("authorization");

        if(StringUtils.isNotBlank(header)){
            ThreadLocalUtil.setUserId(Long.valueOf(header));
        }

        return true;
    }

}
